package org.breathe.dynamic.thread.pool.core.context;

import cn.hutool.core.collection.CollUtil;
import lombok.Builder;
import lombok.Data;
import org.breathe.dynamic.thread.pool.core.thread.BreatheDtpExecutor;
import org.breathe.thread.pool.common.entity.NotifyItem;
import org.breathe.thread.pool.common.entity.NotifyPlatform;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 线程池上下文
 * @author: breathe
 * @createTime: 2025-04-10
 */
@Data
@Builder
public class BreatheDtpContext {

    /**
     * 动态线程池
     */
    private BreatheDtpExecutor breatheDtpExecutor;

    /**
     * 所有的通知平台
     */
    private List<NotifyPlatform> platforms;

    /**
     * 定义线程池报警规则的实体类
     */
    private NotifyItem notifyItem;

    /**
     * 获取平台列表
     * @param platform 平台
     * @return 返回所有平台列表
     */
    public List<NotifyPlatform> getPlatform(String platform) {
        if (CollUtil.isEmpty(platforms)) {
            return null;
        }
        return platforms.stream()
                .filter(each -> each.getPlatform().equalsIgnoreCase(platform))
                .collect(Collectors.toList());
    }
}
